package com.lanlian.cayman.proto;

import com.lanlian.commonlib.dao.DBManager;
import com.oms.rpc.protobuf.CancelOrderInfo;
import com.oms.rpc.protobuf.CancelOrderReq;
import com.oms.rpc.protobuf.FuturesTradeInfo;
import com.oms.rpc.protobuf.FuturesTradeReq;
import com.oms.rpc.protobuf.KLineHqInfo;
import com.oms.rpc.protobuf.KLineHqReq;
import com.oms.rpc.protobuf.KLineHqResp;
import com.oms.rpc.protobuf.OMSTradeReq;
import com.oms.rpc.protobuf.RequestInfo;
import com.oms.rpc.protobuf.TickHqReq;

/**
 * 该类用于参数拼装
 */
public class ProtoManager
{
   private RequestInfo.Builder builder;
    private FuturesTradeInfo.Builder builder2;
    private CancelOrderReq.Builder builder3;
    private CancelOrderInfo.Builder builder_cancel;

    private KLineHqReq.Builder builder_KLineHqReq;
    private KLineHqResp.Builder builder_KLineHqResp;
    private KLineHqInfo.Builder builder_KLineHqInfo;
    private TickHqReq.Builder builder_TickHqReq;

    public ProtoManager()
    {
          initRequestInfo();
          initFuturesTradeInfo();
          initCancelOrderReq();
          initCancel();
          initKLineHqReq();
          initTickHqReq();
    }
    public KLineHqReq.Builder getKLineHqReq()
    {

        return builder_KLineHqReq;
    }
    private void initKLineHqReq()
    {
        builder_KLineHqReq=KLineHqReq.newBuilder();


    }
    public TickHqReq.Builder getTickHqReq()
    {

        return builder_TickHqReq;
    }
    private void initTickHqReq()
    {
        builder_TickHqReq=TickHqReq.newBuilder();


    }
    public FuturesTradeInfo.Builder getFuturesTradeInfoBuilder()
    {
        return builder2;
    }
    public CancelOrderReq.Builder getCancelOrderReqBuilder()
    {
        return builder3;
    }
    public RequestInfo.Builder getInitRequestInfo()
    {
        RequestInfo.Builder  builder = RequestInfo.newBuilder();
        builder.setLRequreId(6000);
        builder.setLTradeType(2);
        builder.setVcToken(DBManager.getInstance().getToken());
        builder.setVcUserId(DBManager.getInstance().getUserId()+"");
        return  builder;
    }
    private void initRequestInfo()
    {
        builder = RequestInfo.newBuilder();
        builder.setLRequreId(6000);
        builder.setLTradeType(2);
        builder.setVcToken(DBManager.getInstance().getToken());
        builder.setVcUserId(DBManager.getInstance().getUserId()+"");

    }
    private void initCancelOrderReq()
    {
        builder3=CancelOrderReq.newBuilder();

    }
    private void initCancel()
    {
        builder_cancel=CancelOrderInfo.newBuilder();
        builder_cancel.setLOperatorNo((int)DBManager.getInstance().getUserId());
    }
    public CancelOrderInfo.Builder getCancelOrderInfo()
    {

        return builder_cancel;
    }
    public CancelOrderInfo.Builder getInitCancelOrderInfo()
    {
        CancelOrderInfo.Builder builder_cancel=CancelOrderInfo.newBuilder();
        builder_cancel.setLOperatorNo((int)DBManager.getInstance().getUserId());
        return builder_cancel;
    }

    public FuturesTradeInfo.Builder getInitFuturesTradeInfo()
    {
        FuturesTradeInfo.Builder builder2=FuturesTradeInfo.newBuilder();
        // builder2.setLAccountId(1);
        // builder2.setCExchangeNo("7");
        builder2.setVcFuturesCode("3");
        builder2.setLOrderAmount(4);
        builder2.setEnOrderPrice(5);
        builder2.setLUnitId(DBManager.getInstance().getUser().getLUnitId());
        builder2.setCOrderDirection("X");

        builder2.setLOperatorNo(DBManager.getInstance().getUserId());
        builder2.setCPriceType("1");

        // builder2.setVcActiveTime("10");
        //  builder2.setVcTif("10");
        // builder2.setLChannelId(0);
        builder2.setLPositionNo(0);
        builder2.setLOrderType(1);
        // builder2.setVcComboffsetFlag("0");
        // builder2.setVcCombhedgeFlag("1");
        return  builder2;
    }
    private void initFuturesTradeInfo()
    {
        builder2=FuturesTradeInfo.newBuilder();
       // builder2.setLAccountId(1);
       // builder2.setCExchangeNo("7");
        builder2.setVcFuturesCode("3");
        builder2.setLOrderAmount(4);
        builder2.setEnOrderPrice(5);
        if(DBManager.getInstance().getUser()!=null)
        {
            builder2.setLUnitId(DBManager.getInstance().getUser().getLUnitId());
        }

        builder2.setCOrderDirection("X");

        builder2.setLOperatorNo(DBManager.getInstance().getUserId());
        builder2.setCPriceType("1");

       // builder2.setVcActiveTime("10");
      //  builder2.setVcTif("10");
       // builder2.setLChannelId(0);
        builder2.setLPositionNo(0);
        builder2.setLOrderType(1);
       // builder2.setVcComboffsetFlag("0");
       // builder2.setVcCombhedgeFlag("1");
    }

    /**
     *   1 返回委托消息包 2撤单消息包3返回测试消息包
     * @param index
     * @return
     */
    public OMSTradeReq.Builder getRequst(int index)
    {
        OMSTradeReq.Builder builder_oms=OMSTradeReq.newBuilder();
        if(index==1)
        {
            builder.setLRequreId(6000);
            builder_oms.setRequestInfo(builder);
            FuturesTradeReq.Builder builder_fr=  FuturesTradeReq.newBuilder();
            builder_fr.addFuturestradeinfo(builder2);
            builder_oms.setFuturestradeReq(builder_fr);
        }
        else if(index==2)
        {
            builder.setLRequreId(6001);
            builder_oms.setRequestInfo(builder);
            builder3.addCancelInfo(builder_cancel);
            builder_oms.setCancelorderReq(builder3);
        }
        else if(index==3)
        {
            builder.setLRequreId(6003);
            builder_oms.setRequestInfo(builder);
//            BathEnableCapitalReq.Builder builder_bc=BathEnableCapitalReq.newBuilder();
//            builder_bc.addReqinfoRecord(builder5);
//            builder_oms.setBathencaptlReq(builder_bc);
            builder_oms.setKlinehqReq(builder_KLineHqReq);


        }
        else if(index==5)
        {
            builder.setLRequreId(6005);
            builder_oms.setRequestInfo(builder);
            builder_oms.setKlinehqReq(builder_KLineHqReq);

        }
        else if(index==6)
        {
            builder.setLRequreId(6006);
            builder_oms.setRequestInfo(builder);
            builder_oms.setTickhqReq(builder_TickHqReq);

        }
        return builder_oms;
    }
}
